﻿Imports System.Data.SqlClient
Public Class ThemKetQua

    Private _strmasv As String
    Private _strtensv As String
    Private _p1 As String

    Sub New(ByVal strmasv As String, ByVal strtensv As String)
        ' TODO: Complete member initialization 
        _strmasv = strmasv
        _strtensv = strtensv
    End Sub

    Sub New(ByVal p1 As String)
        ' TODO: Complete member initialization 
        _p1 = p1
    End Sub

    Private Property SinhVien_ID As Object

    Private Sub btnThem_Click(sender As System.Object, e As System.EventArgs) Handles btnThem.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        Dim TenMonHoc As String
        TenMonHoc = cboMonHoc.SelectedItem.ToString()
        cmd.CommandText = "select* from MonHoc where TenMonHoc ='" + TenMonHoc + "'"

        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim MaMonHoc As String = td.Rows(0)(0).ToString()
        Dim LanThi As Integer
        LanThi = Convert.ToInt16(txtLanThi.Text)
        Dim DiemThi As Double
        DiemThi = Convert.ToDouble(txtDiemThi.Text)
        Dim TongKet As Double
        TongKet = Convert.ToDouble(txtDiemTongKet.Text)
        cmd.CommandText = "INSERT INTO KetQua VALUES('" + MaMonHoc + "','" + SinhVien_ID + "'," + LanThi + "," + DiemThi + "," + TongKet + ")"
        cmd.ExecuteNonQuery()
        con.Close()
        MessageBox.Show("Thêm Dữ Liệu Thành Công!")
        Me.Close()
        Dim frm As New DanhSachKetQua(SinhVien_ID)
        frm.Show()
    End Sub

    Private Sub button1_Click(sender As System.Object, e As System.EventArgs) Handles button1.Click
        Me.Close()
        Dim frm As New DanhSachKetQua(SinhVien_ID)
        frm.Show()
    End Sub

    Private Sub ThemKetQua_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT TenMonHoc FROM MonHoc  order by MonHoc_ID "
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        Dim i As Integer
        For i = 0 To td.Rows.Count - 1 Step i + 1
            Me.cboMonHoc.Items.Add(td.Rows(i)(0))
        Next
        con.Close()
    End Sub
End Class